<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="学生姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stuName">
              <j-popup
                v-model="model.stuName"
                field="stuName"
                org-fields="stu_id,stu_name"
                dest-fields="stuId,stuName"
                code="stu_info"
                :multi="false"
                @input="popupCallback"
                />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="学生编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stuId">
              <a-input v-model="model.stuId" placeholder="请输入学生编号" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="维护人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maintainer">
              <j-popup
                v-model="model.maintainer"
                field="maintainer"
                org-fields="id,realname"
                dest-fields="maintainerId,maintainer"
                code="tj_user_report"
                :multi="false"
                @input="popupCallback"
                />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="维护人编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maintainerId">
              <a-input v-model="model.maintainerId" placeholder="请输入维护人编号" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="维护时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maintainTime">
              <j-date placeholder="请选择维护时间"  v-model="model.maintainTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="维护方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maintainMode">
              <a-input v-model="model.maintainMode" placeholder="请输入维护方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="当前所在城市" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentLocation">
             <j-area-linkage type="cascader" v-model="model.currentLocation" placeholder="请输入省市区"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否转正" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="regularization">
              <a-input v-model="model.regularization" placeholder="请输入是否转正"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="薪资变化" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="changeMoney">
              <a-input v-model="model.changeMoney" placeholder="请输入薪资变化"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="职位变化" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="changePosition">
              <a-input v-model="model.changePosition" placeholder="请输入职位变化"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否换工作" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="changeJob">
              <a-input v-model="model.changeJob" placeholder="请输入是否换工作"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="协助状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="helpStatus">
              <j-dict-select-tag type="list" v-model="model.helpStatus" dictCode="help_status" placeholder="请选择协助状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否需要协助" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="helpRequest">
              <j-dict-select-tag type="list" v-model="model.helpRequest" dictCode="help_Yes_No" placeholder="请选择是否需要协助" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="遇到的问题" :labelCol="labelCol2" :wrapperCol="wrapperCol2" prop="maintainQuestion">
              <a-textarea v-model="model.maintainQuestion" rows="4" placeholder="请输入遇到的问题" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  var d = new Date();
  export default {
    name: 'EmploymenMaintainForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        localPerson:"",
        model:{
            maintainMode:"电话",
            regularization:"是",
            changeMoney:"否/备注",
            changePosition:"否/备注",
            changeJob:"否/备注",
            helpRequest:"1",
            maintainQuestion:"无",
            maintainTime:d.toLocaleString(),
            /*维护人*/
            maintainer:'',
            /*维护人编号*/
            maintainerId:'',
         },
        labelCol2: {
          xs: { span: 24 },
          sm: { span: 3 },
        },
        wrapperCol2: {
          xs: { span: 24 },
          sm: { span: 18 },
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 7 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           stuName: [
              { required: true, message: '请输入学生姓名!'},
           ],
           stuId: [
              { required: true, message: '请输入学生编号!'},
           ],
           maintainer: [
              { required: true, message: '请输入维护人!'},
           ],
           maintainerId: [
              { required: true, message: '请输入维护人编号!'},
           ],
           maintainTime: [
              { required: true, message: '请输入维护时间!'},
           ],
           maintainMode: [
              { required: true, message: '请输入维护方式!'},
           ],
        },
        url: {
          add: "/maintain/employmenMaintain/add",
          edit: "/maintain/employmenMaintain/edit",
          queryById: "/maintain/employmenMaintain/queryById",
          getSysUserInfoUrl:"/maintain/employmenMaintain/getSysUserInfo",
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));

    },
    methods: {
      /*获取当前登录人的信息，填入维护人组件*/
         getSysUserInfo(){
           httpAction(this.url.getSysUserInfoUrl, {},'post').then((res)=>{
             if(res.success){

               this.model.maintainer = res.result.realname;
               this.model.maintainerId = res.result.id;
             }
           })
         },
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        //获取当前登录人的信息
        this.getSysUserInfo();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
      popupCallback(value,row){
         this.model = Object.assign(this.model, row);
      },
    }
  }
</script>